<template>
	<view class="earlyWarning">
		<view class="mail_List">
			<view class="mail" style="font-weight: 700;">
				<view class="order">装修管理</view>
			</view>
		</view>
		<view class="icon">
			<u-icon name="arrow-left" color="#fefefe" size="40" @click="navigateBack"></u-icon>
		</view>
		<u-search :placeholder=placeholder v-model="deviceName" :show-action=false @change="search" >
		</u-search>
		<view>
			<uni-card class="second_card" style="margin: 0;">
				<u-cell-group :border="false" v-if="current==1" v-for="(item,index) in application" :key=index >
					<u-cell-item :title="item.ownerName" arrow-direction="right">
						<u-cell-item :arrow="false" :border-bottom="false" :title="item.address" :value="item.auditStatus=='0' ? '审核中' : item.auditStatus=='1' ? '通过' : '驳回'" @click="owner(item.decorationId)"></u-cell-item>
					</u-cell-item> 
				</u-cell-group>
				<u-cell-group :border="false" v-if="current==2">  
					<u-cell-item title="固定" arrow-direction="right">
						<u-cell-item :arrow="false" :border-bottom="false" :title="searchOwners.ownerName" @click="decorationDetails(deviceName)">
						</u-cell-item>
					</u-cell-item>
				</u-cell-group>
			</uni-card>
		</view>
		<!-- 弹框 -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				placeholder:'请输入手机号',
				current: 1,
				// 搜索内容
				name: '',
				// 所有展示数据
				application:'',
				// 搜索内容
				deviceName: '',
				// 搜索展示数据
				searchOwners: '',
			}
		},
		onLoad() {
			// 展示全部数据
			this.getRecords()
		},
		methods:{
			// 所有数据点击跳转
			owner(decorationId) {
				console.log(decorationId)
					uni.navigateTo({
						url: `/pagesA/application/decoration/decorationDetails/decorationDetails?decorationId=${decorationId}`
					});
			},
			// 展示全部数据
			getRecords() {
				this.loginId = uni.getStorageSync("setModel")
				this.$http.get('informationInquiry/selectPersonnel',{
					loginId:this.loginId.userId,
					deptId:this.loginId.deptId
				}).then(res => {
					console.log(res, '课程分类')
					this.application = res.data
				})
			},
			// 改变搜索框内容触发
			search() {
				// console.log(this.deviceName, 1)
				const self = this;
				// 清空搜索框展示所有数据
				if (this.deviceName == '') {
					console.log(self.deviceName, 2)
					self.getRecords()
					
					self.current = 1
				} else {
					console.log(333)
					// 搜索框防抖功能
					if(this.deviceName !='') {
						clearTimeout(self.timer);
					}
					self.timer = setTimeout(() => {
						// 根据条件搜索数据
						this.$http.get('informationInquiry/selectPersonnelByName', {
							phone: this.deviceName,
							loginId:this.loginId.userId,
							deptId:this.loginId.deptId
						}).then(res => {
							if (res.code == 200) {
								console.log(res, '课程分类')
								this.searchOwners = res.data
								this.current = 2
							} else {
								this.current = 3
								this.$refs.uToast.show({
									title: res.msg,
								})
								console.log(res)
							}
						})
					}, 500)
			
				}
			},
			decorationDetails(deviceName) {
				this.openUrl(`/pagesA/application/decoration/decorationDetails/decorationDetails?deviceName=${deviceName}`)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.earlyWarning {
		.mail_List {
			overflow: hidden;
			width: 100%;
			background-color: #f2f2f2;
		
			.mail {
				height: 160rpx;
				line-height: 230rpx;
				color: #fff;
				font-size: 40rpx;
				background-color: #2a4f65;
			}
		
			.order {
				text-align: center;
			}
		}
		.icon {
			position: absolute;
			top: 96rpx;
			left: 20rpx;
		}
		/deep/.u-search {
			margin: 30rpx 30rpx 0 30rpx !important;
		}
		/deep/.second_card {
		
			.uni-card {
				z-index: unset;
				margin: 24rpx 0;
			}
		
			/deep/.u-cell__value {
				margin-right: -18rpx;
			}
		
			.u-cell {
				padding: 14rpx 0 14rpx 24rpx;
			}
		
			.uni-card__content {
				padding: 0 10rpx !important;
			}
		}
	}
</style>
